package com.vcredit.creditcat.service;

import com.vcredit.creditcat.model.ItemCategory;
import com.vcredit.creditcat.persistence.base.ItemCategoryMapper;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * 
 **/
@Service
public class ItemCategoryService {
	@Autowired
	private ItemCategoryMapper mapper;

	public void insert(ItemCategory obj) {
		mapper.insert(obj);
	}

	public void update(ItemCategory obj) {
		mapper.update(obj);
	}

	@Cacheable(key = "'config:ItemCategorys'", value = "black_simple")
	public Map<Integer, ItemCategory> findAll() {
		Map<Integer, ItemCategory> itemCategorys = new HashMap<Integer, ItemCategory>();
		for (ItemCategory itemCategory : mapper.findAll())
			itemCategorys.put(itemCategory.getCateId(), itemCategory);
		return itemCategorys;
	}

	@SuppressWarnings("unused")
	private List<ItemCategory> find(ItemCategory obj) {
		return mapper.find(obj);
	}

	public ItemCategory findById(Integer cateId) {
		Map<Integer, ItemCategory> itemCategorys = findAll();
		return itemCategorys.get(cateId);
	}
}